/**   
 * Copyright © 2016 北京之洲科技有限责任公司. All rights reserved.
 * 
 * @Title: MainReflect.java 
 * @Prject: carfactory
 * @Package: com.zizo.reflect.reflectmain 
 * @Description: 
 * @author: Alexis  
 * @email heyan0227@outlook.com
 * @date: 2016年8月1日 下午7:07:15 
 * @version: V1.0   
 */
package com.zizo.reflect.reflectmain;

import java.sql.Connection;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.jsoup.nodes.Document;

import com.zizo.autohome.kb.dao.KBDaoOfAutoHome;
import com.zizo.reflect.autohome.bbs.BBSReflectFileOfAutoHome;
import com.zizo.reflect.autohome.kb.KBReflectFileOfAutoHome;
import com.zizo.reflect.autohome.news.NewsPostReflectFileOfAutoHome;
import com.zizo.reflect.autohome.news.NewsReflectFileOfAutoHome;
import com.zizo.reflect.autohome.reply.ReplyReflectFileOfAutoHome;
import com.zizo.util.ConnectionPool;
import com.zizo.util.DocUtil;

/**
 * @ClassName: MainReflect
 * @Description:
 * @author: Alexis
 * @date: 2016年8月1日 下午7:07:15
 */
public class MainReflect {
	public static void main(String[] args) {
		MainReflect.start("autohome", "kb", 30);
	}

	public static void start(String website, String model, int threadCount) {
		ExecutorService fixexecutorservice = Executors.newFixedThreadPool(threadCount);
		Connection currConn = null;
		Connection coreConn = null;
		if (website.equals("autohome")) {
			switch (model) {
			case "bbs":
				// List<String> ips = BBSDaoReflect.getIPs();
				for (int i = 730000; i < 60000000; i++) {
					fixexecutorservice.execute(new BBSReflectFileOfAutoHome(i + ""));
				}
				break;
			case "reply":
				fixexecutorservice.execute(new ReplyReflectFileOfAutoHome("21697561"));
				break;
			case "kb":
				String ip = "localhost";
				currConn = ConnectionPool.getConnection("autohome", ip, "3306");
				coreConn = ConnectionPool.getConnection("carvoice_core", ip, "3306");
				KBDaoOfAutoHome kbdao = new KBDaoOfAutoHome(currConn, coreConn);
				List<String> carIDs = kbdao.getIDs();
				System.out.println("共Car：" + carIDs);
				for (String ids : carIDs) {
					fixexecutorservice.execute(new KBReflectFileOfAutoHome(ids));
				}
				break;
			case "news":
				Document docnews = DocUtil.getDoc("http://www.autohome.com.cn/all/");
				int newsPage = Integer.parseInt(docnews.select("div#channelPage a:not(.page-item-next").last().text());
				for (int i = 1; i < newsPage + 1; i++) {
					fixexecutorservice.execute(new NewsReflectFileOfAutoHome(i + ""));
				}
				break;
			case "newsPost":
				Document docnewsPost = DocUtil.getDoc("http://www.autohome.com.cn/all/");
				int newsPostPage = Integer
						.parseInt(docnewsPost.select("div#channelPage a:not(.page-item-next").last().text());
				for (int i = 1; i < newsPostPage + 1; i++) {
					fixexecutorservice.execute(new NewsPostReflectFileOfAutoHome(i + ""));
				}
				break;
			default:
				break;
			}
		}
		fixexecutorservice.shutdown();
	}

}
